/*
 * Copyright (c) 2022  by Junzhao
 * THIS FILE IS PART OF JAVASE Song Huongkang PROJECT
 * All Rights Reserved.
 */

package 练习.test04;

/**
 * 对象数组 改进
 *
 *
 */

class test04_impro {
    public static void main(String[] args) {

        //**对象数组**
        Student[] st = new Student[20];
        for (int i=0;i< st.length;i++){
            //给数组元素赋值
            st[i] = new Student();
            //给属性赋值
            st[i].number= i+1;
            st[i].score();
            st[i].state();
        }

        System.out.println("*************************");
        state_3(st);
        System.out.println("*************************");
        sort(st);


    }
/**
 * @description 冒泡排序
 * @param [st]
 * @author 俊昭
 * @date 2022/3/16
*/
    public static void sort(Student[] st){
        //对象数组属性的冒泡排序
        for (int i = 0;i < st.length - 1;i++){
            for (int j = 0;j< st.length- 1 - i;j++){
                if (st[j].score > st[j+1].score){
                    //这里交换的是数组的对象
                    Student temp = st[j];
                    st[j] = st[j+1];
                    st[j+1] = temp;
                }
            }
        }
        for(Student student:st){
            System.out.println(student.info());
        }
    }


    public static void state_3(Student[] st){
        //输出三年级的学生信息
        for(Student student:st){
            if (student.state == 3){
                System.out.println(student.info());
            }
        }
    }
}

